<?php

namespace App\Http\Services;

use App\Http\Model\FinanceDiamond;
use App\Http\Model\FinanceUserWallet as FinanceUserWalletModel;
use App\Http\Model\FinanceWealth as FinanceWealthModel;
use App\Http\Model\Hint;
use App\Http\Model\Prop;
use App\Http\Model\GiftBag;
use App\Http\Model\User;
use App\Lib\Publisher;
use Illuminate\Support\Facades\DB;
use App\Http\Model\Room;
use App\Http\Model\RoomHot;
use Illuminate\Support\Facades\Log;

class ActivityServices extends CommonServices
{
    protected $propModel;
    protected $giftBagModel;
    protected $financeUserWalletModel;
    protected $diamondModel;
    protected $financeWealthModel;// 财富值
    protected $ratioConf;
    protected $userModel;
    protected $roomModel;
    protected $roomHotModel;

    public function __construct()
    {
        $this->propModel = new Prop();
        $this->giftBagModel = new GiftBag();
        $this->financeUserWalletModel = new FinanceUserWalletModel();
        $this->diamondModel = new FinanceDiamond();
        $this->financeWealthModel = new FinanceWealthModel();
        $this->ratioConf = config('pay.wallet_change_ratio');
        $this->userModel = new User();
        $this->roomModel = new Room();
        $this->roomHotModel = new RoomHot();

    }

    public function array_group($array, $key)
    {
        $result = [];
        foreach($array as $k=>$v){
            $result[$v[$key]][] = $v;
        }
        return $result;
    }

    /**
     * 获取全部开播中的CBD房间
     * @return array
     */
    public function openRoomCbdAll()
    {
        //所有房间信息
        $list = $this->roomHotModel->getAllRoomHotIdData();
        $list = json_decode($list, true);

        $listEx = [];
        foreach($list as $val) {
            if(isset($val['b']) && $val['b']==1) {
                $listEx[] = $val['r'];
            }
        }

        return $listEx;
    }

    /**
     * 获取全部开播中的房间
     * @return array
     */
    public function openRoomAll($types="")
    {
        //所有已开启的房间
        $list = $this->roomModel->getAllRoomOpenList();
        $roomIds = [];
        foreach($list as $key=>$val) {
            [$roomId, $type] = explode(':', $key);
            $roomIds[] = $roomId;
        }
        $list = array_values(array_unique($roomIds));

        return $list;
    }
}
